//
//  GCMineHomeCollectionHeader.m
//  GoldChampion
//
//  Created by Mac on 2018/4/13.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "GCMineHomeCollectionHeader.h"

@interface GCMineHomeCollectionHeader()
@property(nonatomic, strong) STButton                     *iconButton;
@property(nonatomic, strong) STLabel                     *fansLable;
@property(nonatomic, strong) STLabel                     *attentionLable;

@property(nonatomic, strong) STButton                     *workButton;
@property(nonatomic, strong) STButton                     *customButton;
@property(nonatomic, strong) STButton                     *likeButton;

@property(nonatomic, strong) NSArray                     *buttons;
@end
@implementation GCMineHomeCollectionHeader
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    UIView * clearView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 135)];
    clearView.backgroundColor = [UIColor clearColor];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, clearView.bottom, UIScreenWidth, 135)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:whiteView];
    
    self.iconButton = [[STButton alloc] initWithFrame:CGRectMake(15, clearView.bottom - 25, 70, 70)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:35
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"宋微微"]];
    [self addSubview:self.iconButton];
    
    CGFloat itemwWith = (UIScreenWidth - 30 - self.iconButton.right)/3;
    
    self.fansLable = [[STLabel alloc] initWithFrame:CGRectMake(self.iconButton.right+15, 0, itemwWith, 44)
                                                     text:@"108粉丝"
                                                textColor:SecendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [whiteView addSubview:self.fansLable];
    [self.fansLable st_showRightLine:15];
    
    self.attentionLable = [[STLabel alloc] initWithFrame:CGRectMake(self.fansLable.right, 0, itemwWith, 44)
                                               text:@"998关注"
                                          textColor:SecendTextColor
                                               font:14
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentCenter];
    [whiteView addSubview:self.attentionLable];

    
    STButton * enditButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 90, 25)
                                                     title:@"编辑个人资料"
                                                titleColor:TM_redColor
                                                 titleFont:12
                                              cornerRadius:4
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    enditButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    enditButton.right = UIScreenWidth - 15;
    [enditButton st_setBorderWith:1 borderColor:TM_redColor cornerRadius:4];
    enditButton.centerY = self.attentionLable.centerY;
    [enditButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMineHandle) {
            weakSelf.onSelectedMineHandle(@"编辑");
        }
    }];
    [whiteView addSubview:enditButton];
    
    
    STButton * personButton = [[STButton alloc] initWithFrame:CGRectMake(self.fansLable.left, self.fansLable.bottom, 250, 40)
                                                       title:@"点击此处添加个人介绍"
                                                  titleColor:SecendTextColor
                                                   titleFont:15
                                                cornerRadius:0
                                             backgroundColor:nil
                                             backgroundImage:nil
                                                       image:[UIImage imageNamed:@"编辑介绍"]];
    personButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [personButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMineHandle) {
            weakSelf.onSelectedMineHandle(@"个人介绍");
        }
    }];
    [whiteView addSubview:personButton];
    
    self.workButton = [self defultButtonWithTitle:@"5作品"];
    self.workButton.selected = YES;
    [whiteView addSubview:self.workButton];

    self.customButton = [self defultButtonWithTitle:@"3私密"];
    self.customButton.left = self.workButton.right;
    [whiteView addSubview:self.customButton];
    
    self.likeButton = [self defultButtonWithTitle:@"7喜欢"];
    self.likeButton.left = self.customButton.right;
    [whiteView addSubview:self.likeButton];
}
- (STButton*)defultButtonWithTitle:(NSString*)title{
    CGFloat buttonWith = (UIScreenWidth - 30)/3;
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(15, 0, buttonWith, 44)
                                                     title:title
                                                titleColor:SecendTextColor
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [buyButton setTitleColor:TM_redColor forState:UIControlStateSelected];
    buyButton.bottom = 135 - 5;
    __weak typeof(self) weakSelf =  self;
    [buyButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedMenuButton:sender];
    }];
    return buyButton;
}
- (void)makeMenuButtonSelctedWithIndex:(NSInteger)index{
    self.workButton.selected = NO;
    self.customButton.selected = NO;
    self.likeButton.selected = NO;
    
    if (index == 0) {
        self.workButton.selected = YES;
    }
    if (index == 1) {
        self.customButton.selected = YES;
    }
    if (index == 2) {
        self.likeButton.selected = YES;
    }
}
#pragma mark --Action Method
- (void)onSelctedEditButton{
    
}
- (void)onSelctedMenuButton:(UIButton*)sender{
    self.workButton.selected = NO;
    self.customButton.selected = NO;
    self.likeButton.selected = NO;
    sender.selected = YES;
    if ([sender.currentTitle containsString:@"作品"]) {
        if (self.onSelectedMenuHandle) {
            self.onSelectedMenuHandle(0);
        }
    }
    
    if ([sender.currentTitle containsString:@"私密"]) {
        if (self.onSelectedMenuHandle) {
            self.onSelectedMenuHandle(1);
        }
    }
    
    if ([sender.currentTitle containsString:@"喜欢"]) {
        if (self.onSelectedMenuHandle) {
            self.onSelectedMenuHandle(2);
        }
    }
}

@end
